<!--
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Hyperledger Composer REST server</title>
  <link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='css/loopbackStyles.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='css/composer.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
  <link href='css/print.css' media='print' rel='stylesheet' type='text/css'/>
  <link href='css/loopbackStyles.css' media='print' rel='stylesheet' type='text/css'/>
  <link href='css/composer.css' media='print' rel='stylesheet' type='text/css'/>
  <script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
  <script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
  <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
  <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
  <script src='lib/handlebars-4.0.5.js' type='text/javascript'></script>
  <script src='lib/lodash.min.js' type='text/javascript'></script>
  <script src='lib/backbone-min.js' type='text/javascript'></script>
  <script src='swagger-ui.js' type='text/javascript'></script>
  <script src='lib/highlight.9.1.0.pack.js' type='text/javascript'></script>
  <script src='lib/jsoneditor.min.js' type='text/javascript'></script>
  <script src='lib/marked.js' type='text/javascript'></script>

  <!-- enabling this will enable oauth2 implicit scope support -->
  <script src='lib/swagger-oauth.js' type='text/javascript'></script>

  <!-- Init swagger UI. -->
  <script src='lib/loadSwaggerUI.js' type="text/javascript"></script>
  <script type="text/javascript">
    $(function() {
        $('.accessTokenDisplay').text('Token Set.');
    });
  </script>

  <!-- Display the access token. -->
  <script type="text/javascript">
    function getCookie(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }
    $(function() {
        var access_token = getCookie('access_token');
        if (!access_token) {
            return;
        }
        var matches = access_token.match(/^s:(.+?)\./);
        if (!matches) {
            return;
        }
        access_token = matches[1];
        $('#access-token-value-hide').val('****************************************************************');
        $('#access-token-value-show').val(access_token);
        $('#access-token-toggle').click(function() {
            var text = $(this).text();
            if (text === 'Show') {
                $('#access-token-value-hide').hide();
                $('#access-token-value-show').show();
                $(this).text('Hide');
            } else if (text === 'Hide') {
                $('#access-token-value-hide').show();
                $('#access-token-value-show').hide();
                $(this).text('Show');
            }
        });
        $('#access-token-logout').click(function() {
            window.location.href = '/auth/logout';
        });
        $('#access-token-container').show();
        $('#access-token-value-hide').show();
    });
  </script>
</head>

<body class="swagger-section standalone">
<div id='header'>
    <div class="swagger-ui-wrap">
        <a id="logo"><b>Hyperledger</b> Composer REST server</a>
    </div>
</div>

<div class="contentWell">
    <div id="message-bar" class="swagger-ui-wrap">
    </div>
    <div id="access-token-container">
        <label>Access token</label>
        <br>
        <input id="access-token-value-hide" type="password" disabled></input>
        <input id="access-token-value-show" type="text" readonly></input>
        <button id="access-token-toggle">Show</button>
        <button id="access-token-logout">Logout</button>
        <p>
        The access token displayed above can be used to authenticate to the REST API using a standard
        HTTP or REST client.<br>
        You must specify the access token in the query string
        (<code>?access_token=xxxxx</code>) or as an additional HTTP header (<code>X-Access-Token: xxxxx</code>).
        </p>
    </div>
    <div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</div>
</body>
</html>
